#include "stm32f10x.h"
#include "stm32f10x_it.h"

#include "led.h"
#include "delay.h"
#include "usart.h"
#include "stdio.h"
//#include "key.h"
#include "tim.h"

int main(void)
{
	uint8_t flag = 0;
	uint16_t pwn_value = 0;
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
	LED_Init();
	USART_init(115200);
	Delay_Init();
	//KEY_Init();
	TIM_Init(999,0);
	//printf("this is TIM test 0\n");
	while(1){
		if (flag == 0)
		{
			pwn_value++;
			if (pwn_value>900){
				flag = 1;
			}
		}
		if (flag == 1)
		{

			pwn_value--;
			if (pwn_value==0){
				flag = 0;
			}
		}
		TIM_SetCompare1(TIM3,pwn_value);
		TIM_SetCompare2(TIM3,pwn_value);
		Delay_ms(1);
		
		
		//uint8_t RX_Data;
			//printf("this is TIM test\n");

		
//	  while(USART_GetFlagStatus(USART1,USART_FLAG_RXNE)==RESET);
//		RX_Data = USART_ReceiveData(USART1);
//		USART_SendData(USART1,RX_Data);
//		if (RX_Data == 48){
//				GPIO_ResetBits(GPIOC, GPIO_Pin_13);
//		}
//				if (RX_Data == 49){
//				GPIO_SetBits(GPIOC, GPIO_Pin_13);
//		}
	}
}
